#pragma once

// CFirendCtrl

extern void GradientFillRect( CDC *pDC, CRect &rect, COLORREF col_from, COLORREF col_to, bool vert_grad );

class CFriendCtrl : public CTreeCtrl
{
	typedef map<string,TTChatGlobal::ROSTER_LIST> MAP_GROUPS;
	DECLARE_DYNAMIC(CFriendCtrl)

public:
	CFriendCtrl();
	virtual ~CFriendCtrl();

	// Attributes
	void SetBkGradients( COLORREF from, COLORREF to ){	m_gradient_bkgd_from = from; 
	m_gradient_bkgd_to = to; }
	COLORREF GetBkGradientFrom( ){	return m_gradient_bkgd_from; }
	COLORREF GetBkGradientTo( ){ return m_gradient_bkgd_to; }

	enum BkMode { BK_MODE_BMP = 0, BK_MODE_GRADIENT, BK_MODE_FILL };
	BkMode GetBkMode( ) { return m_bkgd_mode; }
	void SetBkMode( BkMode bkgd_mode ) { m_bkgd_mode = bkgd_mode; }

	bool GetBitmapTiledMode() { return m_bmp_tiled_mode;}
	void SetBitmapTiledMode( bool tiled ) {	m_bmp_tiled_mode = tiled; }

	bool GetGradientHorz() { return m_gradient_horz; }
	void SetGradientHorz( bool horz ) { m_gradient_horz = horz; } 


	virtual void  SetItemIcon( HICON icon ) { m_icon = icon; }; // Overridable
	virtual HICON GetItemIcon( HTREEITEM item ); // Overridable

	// Operations
	bool ItemIsVisible( HTREEITEM item );

	//
	void ChangeSeleletedItem();

	//Image Setting
	void SetBkImage(Image* pImgBk);
	void SetTreeImg(Image* pImgTreeClosed,Image* pImgTreeOpen);
	void SetDefaultHeadImg(Image* pImgHead,Image* pImgHeadOff);

	//Data Setting
	void SetOrgData(TTChatGlobal::ROSTER_MAP mapRoster);		//Init Original Data
	void UpdateRoster(TTChatGlobal::LPROSTER pRoster);			//Update roster


private:
	COLORREF m_gradient_bkgd_from;		// Gradient variables
	COLORREF m_gradient_bkgd_to;
	COLORREF m_gradient_bkgd_sel;
	bool     m_gradient_horz;			// horz or vertical gradient

	BkMode  m_bkgd_mode;				// Current Background mode

	Image*   m_pImgBk;
	Image*   m_pImgTreeClosed;
	Image*   m_pImgTreeOpen;
	Image*   m_pImgHeadOnline;			//Default header online
	Image*   m_pImgHeadOffline;			//Default header offline

	bool     m_bmp_tiled_mode;			// Tile background image

	CRect m_rect;						// The client rect when drawing
	int   m_h_offset;					// 0... -x (scroll offset)
	int   m_h_size;						// width of unclipped window
	int   m_v_offset;					// 0... -y (scroll offset)
	int   m_v_size;						// height of unclipped window

	HICON m_icon;

	void DrawBackGround( CDC* pDC );	// Background Paint code
	void DrawItems( CDC* pDC );  // Item Paint Code

protected:
	afx_msg BOOL OnEraseBkgnd(CDC* pDC);
	afx_msg void OnPaint();
	afx_msg void OnTvnItemexpanding(NMHDR *pNMHDR, LRESULT *pResult);
	afx_msg void OnNMClick(NMHDR *pNMHDR, LRESULT *pResult);
	DECLARE_MESSAGE_MAP()

	void UpdateCtrl();

private:
	MAP_GROUPS m_mapGroups;
};


